<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta name="csrf-param" content="_csrf-backend">
    <title>rettyFrameWork</title>
    {include file="public/meta"/}
</head>

<body class="hold-transition login-page">
<div class="login-box">
    <div class="login-logo">
        PrettyFrameWork
    </div>

    <div class="login-box-body">
        <p class="login-box-msg">欢迎登录</p>

        <form id="loginForm" action="" method="post" onsubmit="return ajaxConfirm(this)">
            <div class="form-group required">
                <div class="form-group has-feedback">
                    <input type="text" id="account" class="form-control"
                     name="account" placeholder="登录账号">
                    <span
                        class="glyphicon glyphicon-user form-control-feedback">
                    </span>
                </div>
                <p class="help-block help-block-error"></p>
            </div>

            <div class="form-group required">
                <div class="form-group has-feedback"><input type="password" id="password" class="form-control" name="password" placeholder="密码">
                    <span class="glyphicon glyphicon-lock form-control-feedback">
                    </span>
                </div>
                <p class="help-block help-block-error"></p>
            </div>

            <div class="form-group">
                <div class="row">
                    <div class="col-sm-7">
                        <input type="text" id="verifyCode" class="form-control" name="verifyCode" placeholder="验证码">
                    </div>
                    <div class="col-sm-5">
                        <img id="verifycode-image" style="vertical-align: middle;height:35px;width:122px;cursor: pointer;" src="{:url('captcha')}" onclick="changeCap(this);" style="cursor:pointer">
                    </div>
                </div>
                <p class="help-block help-block-error"></p>
            </div>

            <!--
            <div class="form-group field-loginform-rememberme">
                <div class="checkbox">
                    <label for="loginform-rememberme">
                        <input type="checkbox" id="loginform-rememberme" name="" checked>
                        记住我
                    </label>
                    <p class="help-block help-block-error"></p>
                </div>
            </div>
            -->
            <div class="form-group">
                <button type="submit" class="btn btn-primary btn-block" name="login-button">登入系统</button>
            </div>
        </form>
        <div class="social-auth-links text-center">
            <p>© 2019 - 2020 PrettyFrame All Rights Reserved.</p>
        </div>
    </div>

</div>

</body>


{include file="public/footer-script"/}

<script>

    function ajaxConfirm(obj){

        if(!obj.elements['account'].value){
            toastr.error('登录账号不能为空');
            return false;
        }

        if(!obj.elements['password'].value){
            toastr.error('登录密码不能为空');
            return false;
        }

        if(!obj.elements['verifyCode'].value){
            toastr.error('验证码不能为空');
            return false;
        }

        $.ajax({
            url:"{:url('admin/login/verify')}",
            dataType:'json',
            type:'post',
            data:$('#loginForm').serialize(),
            success:function(data){
                console.log(data);
                if(data.code==300){
                    layer.closeAll();
                    toastr.error(data.msg);
                    changeCap(document.getElementById('verifycode-image'));
                    return false;
                }else{
                    window.location.href= "<?=url('@admin')?>";
                    return false;
                }
            },
            error:function(res){

            }
        });

        return false;
    }


    function changeCap(obj){
        var src = "{:url('captcha')}";
        obj.src= src + '?'+ '&code=' + Math.random();
    }
</script>

</html>
